package org.dromara.tearoom.domain.vo;

import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
import cn.idev.excel.annotation.ExcelProperty;
import cn.idev.excel.annotation.format.NumberFormat;
import cn.idev.excel.annotation.write.style.*;
import cn.idev.excel.enums.BooleanEnum;
import cn.idev.excel.enums.poi.FillPatternTypeEnum;
import cn.idev.excel.enums.poi.HorizontalAlignmentEnum;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.dromara.common.excel.annotation.ExcelDictFormat;
import org.dromara.common.excel.convert.ExcelDictConvert;
import org.dromara.tearoom.domain.TerOrder;

import java.io.Serial;
import java.io.Serializable;

@Data
@ExcelIgnoreUnannotated
@AutoMapper(target = TerOrder.class)
// 整体样式配置
@HeadStyle(fillPatternType = FillPatternTypeEnum.SOLID_FOREGROUND, fillForegroundColor = 44)  // 表头蓝色背景
@HeadFontStyle(fontHeightInPoints = 12, bold = BooleanEnum.TRUE)  // 表头白色加粗字体
@ContentStyle(horizontalAlignment = HorizontalAlignmentEnum.CENTER)  // 内容居中
@ContentFontStyle(fontHeightInPoints = 11)  // 正文字体大小
@ColumnWidth(18)  // 默认列宽
public class TerOrderExportVo implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 订单id
     */
    @ExcelProperty(value = "订单号")
    @ColumnWidth(25)  // 加宽订单号列
    private String id;

    /**
     * 茶室名称
     */
    @ExcelProperty(value = "茶室名称")
    private String tearoomName;


    /**
     * 入住开始日期时间
     */
    @ExcelProperty(value = "入住开始日期时间")
    @ColumnWidth(20)
    private String startTime;

    /**
     * 入住结束日期时间
     */
    @ExcelProperty(value = "入住结束日期时间")
    @ColumnWidth(20)
    private String endTime;

    /**
     * 预定时间(h)
     */
    @ExcelProperty(value = "预定时间(小时)")
    @ContentStyle(dataFormat = 1,horizontalAlignment = HorizontalAlignmentEnum.CENTER)  // 数值格式保留小数
    private Float presetTime;

    /**
     * 支付方式（微信/支付宝）
     */
    @ExcelProperty(value = "支付方式")
    @ContentStyle(horizontalAlignment = HorizontalAlignmentEnum.CENTER)
    private String paymentMethod;

    /**
     * 订单状态（0-待支付 1-已确认 2-已入住 3-已完成 4-已取消）
     */
    @ExcelProperty(value = "订单状态", converter = ExcelDictConvert.class)
    @ExcelDictFormat(readConverterExp = "0=-待支付,1=-已确认,2=-已入住,3=-已完成,4=-已取消")
    @ContentFontStyle(color = Font.COLOR_RED)  // 状态红色显示
    private String orderStatus;

    /**
     * 订单总价 单位:分
     */
    @ExcelProperty(value = "订单总价(元)")
    @NumberFormat("#,##0.00")  // 千分位显示
    @ContentStyle(dataFormat = 4,horizontalAlignment = HorizontalAlignmentEnum.CENTER)  // 货币格式
    private Double  totalPrice;


    /**
     * 预付金额 单位:分
     */
    @ExcelProperty(value = "预付金额(元)")
    @NumberFormat("#,##0.00")
    private Double prepayAmount;

    /**
     * 预计收入 单位:分
     */
    @ExcelProperty(value = "预计收入(元)")
    @NumberFormat("#,##0.00")
    @ContentFontStyle(bold = BooleanEnum.TRUE, color = Font.COLOR_RED)  // 加粗红色
    private Double revenue;

    /**
     * 入住人电话
     */
    @ExcelProperty(value = "入住人电话")
    @ColumnWidth(15)
    private String mobile;

    /**
     * 优惠劵id
     */
    @ExcelProperty(value = "优惠劵ID")
    @ContentStyle(horizontalAlignment = HorizontalAlignmentEnum.RIGHT)
    private Long couponId;

    // 添加金额转换方法（如果数据库存储的是分）
    public void setTotalPrice(Integer totalPrice) {
        this.totalPrice = totalPrice != null ? totalPrice / 100.0 : null;
    }

    public void setPrepayAmount(Integer prepayAmount) {
        this.prepayAmount = prepayAmount != null ? prepayAmount / 100.0 : null;
    }

    public void setRevenue(Integer revenue) {
        this.revenue = revenue != null ? revenue / 100.0 : null;
    }

}
